//
//  MYRollCollectionView.swift
//  积分商城
//
//  Created by apple on 2016/12/6.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

class MYRollCollectionView: UICollectionView {

    fileprivate var imgArray:[Any]?

    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        super.init(frame: frame, collectionViewLayout: layout)
        loadData()
        self.dataSource = self;
        self.register(MYRollCollectionViewCell.self, forCellWithReuseIdentifier: "cell")

    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")

    }
    override func layoutSubviews() {
        super.layoutSubviews()
        let layout = self.collectionViewLayout as!UICollectionViewFlowLayout
        layout.itemSize = self.size
        layout.minimumInteritemSpacing = 0
        layout.minimumLineSpacing = 0
        layout.scrollDirection = .horizontal

    }

}

extension MYRollCollectionView : UICollectionViewDataSource{

    override func numberOfItems(inSection section: Int) -> Int {
        return 10
    }
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return  4;
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! MYRollCollectionViewCell

      return cell
    }
    fileprivate func loadData(){
        let dict = ["call":1]
        DSHTTPClient.postUrlString("focus.json.php", withParam: dict, withSuccessBlock: { (res) in
          print("请求成功",res!)
            guard let result = res as?[String: Any] else{
                return
            }
            let res1 = result["data"] as! [String: Any]
            ///列表
            let res2 = res1["activities"] as! [Any]
          print(res2)
         self.imgArray = NSArray.yy_modelArray(with: MYHomeModel.self, json: res2)

        }, withFailedBlock: { (error) in
            print("请求失败")
        }, withErrorBlock: nil)
    }



}
